/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Ajax;

import DTO.ToaDTO;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Tu Nguyen
 */
@WebServlet(name = "LstGG", urlPatterns = {"/LstGG"})
public class LstGG extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
          if(request.getParameter("so_hieu") != null)
          {
              String maToa  = request.getParameter("so_hieu") ;
              int LoaiToa  = Integer.parseInt(request.getParameter("LoaiToa") );
              if(LoaiToa == 1)// ghe
              {
                  ResultSet rs = BUS.GheBUS.TimGheCuaToa(maToa);
                  while(rs.next())
                  {
                      if(rs.getString("tinh_trang").equals("1"))
                      {
                         String pr = "";
                         pr+= "<button onclick='onc(this)'  class='hihi btn btn-success' style='float:left; margin:3px; width:100px; height:100px'  id="+rs.getString("so_hieu") +">";
                        pr +=rs.getString("so_hieu");
                        pr += "<br/>Chưa đặt";
                        pr += "</button>";
                        out.println(pr);
                      }
                      else if(rs.getString("tinh_trang").equals("2"))// da dat
                      {
                        String pr = "";
                        pr+= "<button disabled class='btn btn-danger' style='float:left; margin:3px; width:100px; height:100px'>";
                        pr +=rs.getString("so_hieu");
                        pr += "<br/>Đã đăt";
                        pr += "</button>";
                        out.println(pr);
                      }
                  }
              }
          }
               //giuong nam
              
                  if(request.getParameter("tang")!= null && request.getParameter("phong")!= null)
                  {
                      int tang = Integer.parseInt(request.getParameter("tang"));
                      String phong = request.getParameter("phong");
                       ResultSet rs = BUS.GiuongBUS.TimGiuongTheoPhong(phong, tang);
                        while(rs.next())
                        {
                            if(rs.getString("tinh_trang").equals("1"))
                            {
                               String pr = "";
                               pr+= "<button onclick='onc(this)'  class='hihi btn btn-success' style='float:left; margin:3px; width:100px; height:100px'  id="+rs.getString("so_hieu") +">";
                              pr +=rs.getString("so_hieu");
                              pr += "<br/>Chưa đặt";
                              pr += "</button>";
                              out.println(pr);
                            }
                            else if(rs.getString("tinh_trang").equals("2"))// da dat
                            {
                              String pr = "";
                              pr+= "<button disabled class='btn btn-danger' style='float:left; margin:3px; width:100px; height:100px'>";
                              pr +=rs.getString("so_hieu");
                              pr += "<br/>Đã đăt";
                              pr += "</button>";
                              out.println(pr);
                            }
                        }
                  }
        }
        catch(Exception ex)
        {}
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
